package cn.sunxyz.behavior.iterator;

/**
 * Created by yangrd on 2017/5/13.
 */
public class MyIterator<T> implements Iterator<T> {
    private int cursor = -1;
    private Collection<T> collection;

    public MyIterator(Collection<T> collection) {
        this.collection = collection;
    }

    @Override
    public boolean hasNext() {
        return collection.size() - 1 > cursor;
    }

    @Override
    public T next() {
        return collection.get(++cursor);
    }

    @Override
    public T first() {
        cursor = 0;
        return collection.get(cursor);
    }
}
